package com.example.zhihu.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.example.zhihu.R;
import com.example.zhihu.bean.FuliBean;

import org.w3c.dom.Text;

import java.util.List;

public class SectionsAdapter extends RecyclerView.Adapter<SectionsAdapter.ViewHolder> {
    private Context context;
    private List<FuliBean.ResultsBean> datas;

    public SectionsAdapter(Context context, List<FuliBean.ResultsBean> datas) {
        this.context = context;
        this.datas = datas;
    }

    @NonNull
    @Override
    public SectionsAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View inflate = LayoutInflater.from(context).inflate(R.layout.item_sections, parent, false);
        return new ViewHolder(inflate);
    }

    @Override
    public void onBindViewHolder(@NonNull SectionsAdapter.ViewHolder holder, int position) {
        FuliBean.ResultsBean resultsBean = datas.get(position);
        holder.text.setText(resultsBean.getWho());
        Glide.with(context).load(resultsBean.getUrl()).into(holder.image);
    }

    @Override
    public int getItemCount() {
        return datas.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        TextView text;
        ImageView image;
        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            text=itemView.findViewById(R.id.item_text);
            image=itemView.findViewById(R.id.item_image);
        }
    }
}
